package com.yaoweigroup.community.adapter;

import java.util.List;

import com.yaoweigroup.community.R;
import com.yaoweigroup.community.enity.SportShop;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class SportGridViewAdapter extends BaseAdapter {
	private LayoutInflater inflater;
	private List<SportShop> items;
	public int selectPosition = -1;

	public SportGridViewAdapter(Context context, List<SportShop> items) {
		this.items = items;
		inflater = LayoutInflater.from(context);

	}

	@Override
	public int getCount() {
		return items.size();
	}

	@Override
	public Object getItem(int position) {
		return items.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = this.inflater.inflate(
					R.layout.adapter_sport_gridview_item, null);
			// holder.tv = (TextView) convertView.findViewById(R.id.tv);
			holder.rl = (RelativeLayout) convertView.findViewById(R.id.rl);
			holder.time_num_tv = (TextView) convertView
					.findViewById(R.id.time_num_tv);
			holder.price_num_tv = (TextView) convertView
					.findViewById(R.id.price_num_tv);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		// holder.tv.setText(items.get(position));
		if (selectPosition == position) {
			holder.rl.setBackgroundColor(Color.parseColor("#DDDDDD"));
			// holder.tv.setTextColor(Color.WHITE);
		} else {
			holder.rl
					.setBackgroundResource(R.drawable.wb_personal_item_full_normal);
			// holder.tv.setTextColor(Color.parseColor("#333333"));
		}
		SportShop shop = items.get(position);
		holder.time_num_tv.setText(shop.getBeginTime() + "-"
				+ shop.getEndTime());
		holder.price_num_tv.setText(shop.getPrice() + "元/小时");
		return convertView;
	}

	public void setDataChange(List<SportShop> times) {

		this.items = times;
		notifyDataSetChanged();
	}

	private class ViewHolder {
		TextView tv;
		RelativeLayout rl;
		TextView time_num_tv;
		TextView price_num_tv;
	}

	public void setPosition(int position) {

		this.selectPosition = position;
		notifyDataSetChanged();
	}

}
